package com.example.controller;

import com.example.service.ExportService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by douyx on 2018/03/21.
 */
@RestController
@RequestMapping("api/export")
public class ExportController {

	@Autowired
	private ExportService exportService;

	/**
	 * 导出维保记录
	 * 
	 * @param map
	 *            elevatorType: 1、曳引与强制驱动电梯  2、液压驱动电梯  3、杂物电梯  4、自动扶梯与自动人行道
	 *            halfMonId: 半月保编号
	 *            elevatorId:电梯编号
	 * @return map
	 *            fileName:文件名
	 *            fileUrl:路径
	 */
	@ApiOperation(value = "导出维保记录", notes = "导出维保记录")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "elevatorType", value = "1、曳引与强制驱动电梯  2、液压驱动电梯  3、杂物电梯  4、自动扶梯与自动人行道", required = true, dataType = "String"),
			@ApiImplicitParam(name = "halfMonId", value = "半月保编号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "elevatorId", value = "电梯编号", required = true, dataType = "String")})
	@RequestMapping(value = "/maint", method = RequestMethod.POST)
	Map<String, Object> exportMaintRecord(@RequestBody Map<String, Object> param) {
		return exportService.exportMaintRecord(param);
	}

	/**
	 * 导出日常巡检记录 月度报表
	 * 
	 * @param map
	 *            month: 月份 yyyyMM
	 *            elevatorId:电梯编号
	 *            elevatorType:电梯类型
	 * @return map
	 *            fileName:文件名
	 *            fileUrl:路径
	 */
	@ApiOperation(value = "导出日常巡检记录 月度报表", notes = "导出日常巡检记录 月度报表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "month", value = "月份 yyyyMM", required = true, dataType = "String"),
			@ApiImplicitParam(name = "elevatorId", value = "电梯编号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "elevatorType", value = "电梯类型", required = true, dataType = "String")})
	@RequestMapping(value = "/daily", method = RequestMethod.POST)
	Map<String, Object> exportDailyInspection(@RequestBody Map<String, Object> param) {
		String elevatorType = param.get("elevatorType")+"";
		if("4".equals(elevatorType) || "6".equals(elevatorType)){
			return exportService.exportDailyFtInspection(param);
		}else{
			return exportService.exportDailyInspection(param);
		}

	}

	/**
	 * 导出电梯应急演练记录
	 * 
	 * @param id: 电梯应急演练编号
	 * @return map
	 *            fileName:文件名
	 *            fileUrl:路径
	 */
	@ApiOperation(value = "导出电梯应急演练记录", notes = "导出电梯应急演练记录")
	@ApiImplicitParam(name = "id", value = "电梯应急演练编号", required = true, dataType = "String")
	@RequestMapping(value = "/rescueDrill/{id}", method = RequestMethod.POST)
	Map<String, Object> exportRescueDrill(@PathVariable(value = "id") String id) {
		return exportService.exportRescueDrill(id);
	}

	/**
	 * 导出电梯应急救援记录
	 * 
	 * @param id: 电梯应急救援编号
	 * @return map
	 *            fileName:文件名
	 *            fileUrl:路径
	 */
	@ApiOperation(value = "导出电梯应急救援记录", notes = "导出电梯应急救援记录")
	@ApiImplicitParam(name = "id", value = "电梯应急救援编号", required = true, dataType = "String")
	@RequestMapping(value = "/emergencyRescue/{id}", method = RequestMethod.POST)
	Map<String, Object> exportEmergencyRescue(@PathVariable(value = "id") String id) {
		return exportService.exportEmergencyRescue(id);
	}

	/**
	 * 导出筛选出的主体单位名单
	 * 
	 * @param map
	 * @return map
	 */
	@ApiOperation(value = "导出筛选出的主体单位名单", notes = "导出筛选出的主体单位名单")
	@RequestMapping(value = "/randomList", method = RequestMethod.POST)
	Map<String, Object> exportRandomList(@RequestBody Map<String, Object> param) {
		return exportService.exportRandomList(param);
	}

	/**
	 * 批量导出电梯的维保记录、维修记录、巡检记录、救援记录、年度自检等信息
	 *
	 * @param param
	 * @return map
	 *            fileName:文件名
	 *            fileUrl:路径
	 */
	@ApiOperation(value = "批量导出电梯作业记录", notes = "批量导出电梯作业记录")
	@RequestMapping(value = "/batch", method = RequestMethod.POST)
	Map<String, Object> batchExportWorkRecords(@RequestBody Map<String, Object> param) {
		return exportService.batchExportWorkRecords(param);
	}
}
